﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace StuApart
{
    public partial class StudentIn : Form
    {
  
        public StudentIn()
        {
            InitializeComponent();
        }

        private void studentInBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            if (nameTextBox.Text.Length == 0)
            {
                MessageBox.Show("姓名不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                nameTextBox.Focus();
                return;
            }
            if (noTextBox.Text.Length == 0)
            {
                MessageBox.Show("学号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                noTextBox.Focus();
                return;
            }
            try
            {
                this.Validate();
                studentInBindingSource1.EndEdit();
                this.studentInBindingSource.EndEdit();
                this.tableAdapterManager.UpdateAll(this.stuApartDataSet);
                MessageBox.Show("保存成功");
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "保存失败");
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“stuApartDataSet.ForIn”中。您可以根据需要移动或移除它。
            this.forInTableAdapter.Fill(this.stuApartDataSet.ForIn);
            // sexComboBox.SelectedIndex = 0;
            // TODO: 这行代码将数据加载到表“stuApartDataSet.StudentIn”中。您可以根据需要移动或移除它。
            this.studentInTableAdapter.Fill(this.stuApartDataSet.StudentIn);

        }

        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            if (studentInDataGridView.SelectedRows.Count == 0)
            {
                MessageBox.Show("请先单击最左边的空白处，选择要删除的行，" + "按住CTRL或Shift键可同时选择多行");
            }
            else
            {
                if (MessageBox.Show("确定要删除选定的行吗？", "小心", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    for (int i = 0; i < studentInDataGridView.SelectedRows.Count; i++)
                    {
                        studentInBindingSource.RemoveAt(studentInDataGridView.SelectedRows[i].Index);
                    }
                }
            }
        }

        private void noTextBox_Validating(object sender, CancelEventArgs e)
        {
            if (noTextBox.Text.Trim().Length != 5)
            {
                MessageBox.Show("学号必须是5位数字", "注意");
                noTextBox.Focus();
            }
        }

      

        private void button1_Click(object sender, EventArgs e)
        {
            string conditionStr = "";
            if (textBox1.Text.Trim() != "")
            {
                if (conditionStr == "")
                    conditionStr = "No LIKE'" + textBox1.Text.Trim() + "%'";
              
            }
            studentInBindingSource.Filter = conditionStr;
           
                }

        private void button2_Click(object sender, EventArgs e)
        {

        }
           
                     
        }
    }

